import numpy as np
import acl
import os

class TestAddOperator
    def setup_method(self)
        acl.init()
        self.stream = acl.rt.create_stream()
        
        # 加载算子
        op_path = os.path.abspath(.buildoutputlibadd_custom.so)
        acl.op.load(op_path)
        
    def test_add_operator(self)
        # 准备数据
        x = np.random.rand(1024).astype(np.float32)
        y = np.random.rand(1024).astype(np.float32)
        z = np.zeros(1024, dtype=np.float32)
        
        # 设备内存分配
        x_dev = acl.util.numpy_to_ptr(x)
        y_dev = acl.util.numpy_to_ptr(y)
        z_dev = acl.util.numpy_to_ptr(z)
        
        # 执行算子
        add_custom(x_dev, y_dev, z_dev, np.uint32(1024), self.stream)
        acl.rt.synchronize_stream(self.stream)
        
        # 验证结果
        expected = x + y
        result = acl.util.ptr_to_numpy(z_dev, (1024,), np.float32)
        assert np.allclose(result, expected, atol=1e-5)
        
    def teardown_method(self)
        acl.rt.destroy_stream(self.stream)
        acl.finalize()

if __name__ == __main__
    test = TestAddOperator()
    test.setup_method()
    test.test_add_operator()
    test.teardown_method()